﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DotNetExtensions.Core.IOC
{
    public class RegistTypeResolver : Singleton<RegistTypeResolver>
    {
        private RegistTypeResolver() { }
        public ContainerBuilder Builder { get; set; }
        public static T Resolve<T>()
        {
            if (Default.Builder == null || !Default.Builder.IsRegistered(typeof(T))) throw new Exception($"Type [{typeof(T)}] not registed");
            return Default.Builder.Resolve<T>();
        }
        public static object Resolve(string typeFullName)
        {
            if (Default.Builder == null || !Default.Builder.IsRegistered(typeFullName)) throw new Exception($"Type [{typeFullName}] not registed");
            return Default.Builder.Resolve(typeFullName);
        }

        public static object Resolve(Type type)
        {
            if (Default.Builder == null || !Default.Builder.IsRegistered(type)) throw new Exception($"Type [{type.FullName}] not registed");
            return Default.Builder.Resolve(type);
        }
        public static object Resolve(Type type, params Type[] parameters)
        {
            if (Default.Builder == null || !Default.Builder.IsRegistered(type)) throw new Exception($"Type [{type.FullName}] not registed");
            return Default.Builder.Resolve(type, parameters);
        }

        public static T Resolve<T>(params Type[] parameters)
        {
            if (Default.Builder == null || !Default.Builder.IsRegistered(typeof(T))) throw new Exception($"Type [{typeof(T)}] not registed");
            return Default.Builder.Resolve<T>(parameters);
        }

        public static object ResolveNamed(string name, Type type)
        {
            if (Default.Builder == null || !Default.Builder.IsRegisteredWithName(name, type)) throw new Exception($"Named [{name}] with type [{type.FullName}] not registed");
            return Default.Builder.ResolveNamed(name, type);

        }
        public static object ResolveNamed(string name, Type type, params Type[] parameters)
        {
            if (Default.Builder == null || !Default.Builder.IsRegisteredWithName(name, type)) throw new Exception($"Named [{name}] with type [{type.FullName}] not registed");
            return Default.Builder.ResolveNamed(name, type, parameters);
        }
    }
}
